﻿@inherits AdminCompontentBase
<AlarmChart AlarmHistory="AlarmHistory" OnClick="HandleOnClick" />
<DefaultSubTitle>@T("CheckFrequency")</DefaultSubTitle>
<div class="d-flex justify-space-between">
    <span class="regular--text body2">
        @if (AlarmHistory.AlarmRule.CheckFrequency.Type == AlarmCheckFrequencyTypes.FixedInterval)
        {
            @AlarmHistory.AlarmRule.CheckFrequency.FixedInterval.IntervalTime @T(AlarmHistory.AlarmRule.CheckFrequency.FixedInterval.IntervalTimeType.ToString())
        }
        @if (AlarmHistory.AlarmRule.CheckFrequency.Type == AlarmCheckFrequencyTypes.Cron)
        {
            @AlarmHistory.AlarmRule.CheckFrequency.CronExpression
        }
    </span>
    <span class="emphasis2--text body2">@T(AlarmHistory.AlarmRule.CheckFrequency.Type.ToString())</span>
</div>
<DefaultSubTitle>@T("VariableInfo")</DefaultSubTitle>
@if (AlarmHistory.AlarmRule.Type == AlarmRuleTypes.Log)
{
    @foreach (var item in AlarmHistory.AlarmRule.LogMonitorItems)
    {
        <div class="d-flex justify-space-between mb-6">
            <div class="regular--text body2">
                @item.Alias
            </div>
            <div class="emphasis2--text body2">
                <span>@item.Field</span>
                <span class="ml-2">@T("Count")</span>
                <span class="ml-2">@(item.IsOffset ? string.Format(T("OffsetPeriod"), item.OffsetPeriod) : string.Empty)</span>
            </div>
        </div>
    }
}
@if (AlarmHistory.AlarmRule.Type == AlarmRuleTypes.Metric)
{
    @foreach (var item in AlarmHistory.AlarmRule.MetricMonitorItems)
    {
        <div class="d-flex justify-space-between mb-6">
            @if (item.IsExpression)
            {
                <div class="fill-background regular--text body2 rounded-r-lg px-4 py-2 flex-grow-1 mr-6">
                    @item.Expression
                </div>
                <div class="emphasis2--text body2">
                    <span>@item.Alias</span>
                    <span class="ml-2">@(item.IsOffset ? string.Format(T("OffsetPeriod"), item.OffsetPeriod) : string.Empty)</span>
                </div>
            }
            else
            {
                <div class="regular--text body2">
                    @item.Alias
                </div>
                <div class="emphasis2--text body2">
                    <span>@item.Aggregation.Name</span>
                    <span class="ml-2">@item.Aggregation.Tag @T(item.Aggregation.ComparisonOperator.ToString()) @item.Aggregation.Value</span>
                    <span class="ml-2">@T(item.Aggregation.AggregationType.ToString())</span>
                    <span class="ml-2">@(item.IsOffset ? string.Format(T("OffsetPeriod"), item.OffsetPeriod) : string.Empty)</span>
                </div>
            }
        </div>
    }
}
<DefaultSubTitle>@T("AlarmInfo")</DefaultSubTitle>
<div class="d-flex justify-space-between mb-6">
    <div class="regular--text body2">
        @T("AlarmTime")
    </div>
    <div class="emphasis2--text body2">
        @AlarmHistory.LastAlarmTime.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateTimeFormat"))
    </div>
</div>
<DefaultSubTitle>@T("TriggerRules")</DefaultSubTitle>
@foreach (var item in AlarmHistory.RuleResultItems)
{
    <div class="d-flex justify-space-between mb-6" style="@(item.IsValid?"":"opacity: 0.6")">
        <div class="regular--text body2">
            <AlertSeverityTag Value="@item.AlarmRuleItem.AlertSeverity" />
        </div>
        <div class="emphasis2--text body2">
            <div class="d-flex">
                <MSwitch Value="item.AlarmRuleItem.IsNotification" Inset Class="label my-auto" Disabled>
                    <LabelContent>
                        <span class="body2 emphasis2--text">@T("AlarmNotification")</span>
                    </LabelContent>
                </MSwitch>
                <MSwitch Value="item.AlarmRuleItem.IsRecoveryNotification" Inset Class="label my-auto ml-6" Disabled>
                    <LabelContent>
                        <span class="body2 emphasis2--text">@T("RecoveryNotification")</span>
                    </LabelContent>
                </MSwitch>
            </div>
        </div>
    </div>
    <div class="d-flex justify-space-between mb-6" style="@(item.IsValid?"":"opacity: 0.6")">
        <div class="regular--text body2 flex-grow-1 pr-6">
            @if (!string.IsNullOrEmpty(item.AlarmRuleItem.Expression))
            {
                <MBorder Color="@(item.IsValid?"green":"regular3--text")" Width="4" Class="rounded-tl-sm rounded-bl-sm"><JsonPre Class="rounded-r-lg fill-background" @bind-Value="@item.AlarmRuleItem.Expression"></JsonPre></MBorder>
            }
        </div>
        <div class="body2 emphasis2--text">@T("TriggerRules")</div>
    </div>
}
@if (HandleStatusShow)
{
    <DefaultTitle>@T("HandleDetails")</DefaultTitle>
    <StatusTimeline StatusCommits="@AlarmHistory.HandleStatusCommits" />
}